home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
388
< prev
next >
Wrap
Text File
|
1996-08-06
|
3KB
|
64 lines
Path: tko.dec.com!diamond
From: diamond@tko.dec.com (Norman Diamond)
Newsgroups: comp.std.c
Subject: Re: struct pointer compatability...
Date: 15 Feb 1996 02:12:50 GMT
Organization: Digital Equipment Corporation Japan , Tokyo
Message-ID: <4fu4r2$io4@usenet.pa.dec.com>
References: <4fq4sn$kkv@solutions.solon.com>
Reply-To: diamond@jrdv04.enet.dec-j.co.jp (Norman Diamond)
NNTP-Posting-Host: jit533.tko.dec.com
In article <4fq4sn$kkv@solutions.solon.com>, seebs@solutions.solon.com (Peter Seebach) writes:
[...]
>Obviously, this is for producing generic linked list code.
>struct a {
> struct a *next;
> int i;
>};
>struct b {
> struct b *next;
>};
> struct a foo [...] ;
> [...] (struct b *) &foo [...]
[...]
>Can anyone tell me where this violates the standard, if it does at
>all? I believe it to be conforming because (I think) pointers to structs
>are compatible as pointers, but I can't find evidence of that anywhere.
You should know how to find that pointers to compatible structure types
are compatible, and then you should be able to guess why the standard
didn't pointers to incompatible structure types also be compatible.
>I am pretty comfortable with the assertion that this is legal *if*
>(struct a *) and (struct b *) have equivalent representations;
Nope. This would make it possible to cast a (pointer) value of type
(struct a *) to type (struct b *) and cast it back to (struct a *) and
then use it, but not to use the cast value with type (struct b *).
However, if they don't have representations that are either equivalent
or close enough to equivalent, then one of these casts will hit you.
>I see no problem with the assertion that the "next" member is in the same
>position in each, I just can't show that it has the same representation.
Right. In addition to that, it is possible for the structure types to
have differing alignment requirements so that most casts will fail.
For example, struct a might have to be aligned on a 15-byte boundary
because it contains a 5-byte pointer, 1-byte pad, and 3-byte int, while
struct b might have to be aligned on a 4-byte boundary because it
contains only a 4-byte pointer.
(Under such an implementation, a pointer to an incomplete struct type can
probably point to any char boundary and therefore requires 8 bytes :-)
>FUCK the communications decency act. Goddamned government. [literally.]
>The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
And in other news today, the US government seized machine rtfm.mit.edu. Next
they'll arrest everyone who talks about a FAQ because of what it sounds like.
--
<< If this were the company's opinion, I would not be allowed to post it. >>
"I paid money for this car, I pay taxes for vehicle registration and a driver's
license, so I can drive in any lane I want, and no innocent victim gets to call
the cops just 'cause the lane's not goin' the same direction as me" - J Spammer